//
//  GaoImageBrowserViewCellModel.m
//  DuTe
//
//  Created by Gikki Ares on 2020/12/24.
//  Copyright © 2020 vgemv. All rights reserved.
//

#import "JsImageBrowserViewCellModel.h"

@implementation JsImageBrowserViewCellModel

- (CGRect)aspectFitFrameForImage:(UIImage *)image inBounds:(CGRect)rect {
	CGFloat w_image = image.size.width;
	CGFloat h_image = image.size.height;
	
	
	CGFloat w_container = rect.size.width;
	CGFloat h_container = rect.size.height;
	
	
	CGFloat scale_w = w_image/w_container;
	CGFloat scale_h = h_image/h_container;
	
	
	CGFloat w_imageView = 0;
	CGFloat h_imageView = 0;
	if(scale_w>=scale_h) {
		//宽度占满,并计算高度
		w_imageView = w_container;
		h_imageView = w_imageView * h_image / w_image;
	}
	else {
		//高度占满,计算宽度
		h_imageView = h_container;
		w_imageView = h_imageView * w_image / h_image;
	}
	
	CGFloat x_imageView = (w_container-w_imageView)/2;
	CGFloat y_imageView = (h_container-h_imageView)/2;
	
	return CGRectMake(x_imageView, y_imageView, w_imageView, h_imageView);
	
}


@end
